// 渲染行车记录的历史信息

function render_history(resultBody) {

    var result_str = "";

    for (var i = 0; i < resultBody.length; i++) {

        var now_info = resultBody[i];

        var str_info;

        str_info = "<tr>"
            + "<td>"
            + now_info.go_time
            + "</td>"
            + "<td>"
            + now_info.place_departure
            + "</td>"
            + "<td>"
            + now_info.destination
            + "</td>"
            + "<td>"
            + now_info.regedate
            + "</td>"
            + "</tr>";

        // console.log(str_info);
        result_str = result_str + str_info

    }

    console.log(result_str)

    return result_str
}
//history接口请求
function getHistory(user_id, access_token) {

    var xmlhttp = new XMLHttpRequest;//新建一个变量名
    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            var result = JSON.parse(xmlhttp.responseText) //相当于python的json.loads方法

            if (result.status == 1) {
                // alert(result);
                console.log(result);

                var result_str = render_history(result.resultBody);

                document.getElementById('tbody').innerHTML = result_str;


            } else {
                alert(result.errorMsg);
                location.href = '/static/login.html'
            }
        }
    }
    //这里是发起请求
    var url = "/app_get_history"
    // alert(url)
    xmlhttp.open("POST", url, true);
    xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlhttp.send("user_id=" + user_id + "&access_token=" + access_token);

}
